<template>
	<view class="bg">
		<view class="head">
			<image class="head_left" src="../../../static/wode/return.png" mode="" @tap="back()"></image>
			<view class="head_mid" v-if="setPass">
				设置密码
			</view>
			<view class="head_mid" v-else>
				注册
			</view>
			<view class="head_right">

			</view>
		</view>
		<view class="body">
			<view class="body_item">
				<image class="passimg" src="../../../static/index/mima.png" mode=""></image>
				<input type="password" v-model="newPass" placeholder="密码由6-20位数字字母组成" :value="inputClearValue" @input="bindClearInput" />
				<image class="delete" src="../../../static/index/delete.png" mode="" v-if="showClearIcon" @click="clearIcon"></image>
			</view>
			<view class="body_item">
				<image class="passimg" src="../../../static/index/mima.png" mode=""></image>
				<input type="password" v-model="newPass2" placeholder="重复输入密码" :value="inputClearValue" @input="bindClearInput" />
				<image class="delete" src="../../../static/index/delete.png" mode="" v-if="showClearIcon" @click="clearIcon"></image>
			</view>
			
			<view class="body_item">
				<image class="passimg" src="../../../static/index/mima.png" mode=""></image>
				<input type="password" value="" placeholder="密码由6-20位数字字母组成" v-model="password" @blur="verifyPassword" />
				<image class="delete" src="../../../static/index/delete.png" mode="" v-if="showClearIcon" @click="clearIcon"></image>
			</view>
			<view class="body_item">
				<image class="passimg" src="../../../static/index/mima.png" mode=""></image>
				<input type="password" value="" placeholder="重复输入密码" v-model="respassword" @blur="resPassword" />
				<image class="delete" src="../../../static/index/delete.png" mode="" v-if="showClearIcon" @click="clearIcon"></image>
			</view>

		</view>
		<view class="btn" @tap="toSetPass" v-if="setPass">
			确定
		</view>
		<view class="btn" @tap="toSupplement" v-else>
			完善个人资料
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				inputClearValue: "",
				showClearIcon: false,
				setPass: false,
				isshouji: false,
				newPass:"",
				newPass2:'',
			};
		},
		onLoad(option) {
			if (option.setPass != undefined) {
				this.setPass = option.setPass
			}
			if (option.isshouji != undefined) {
				this.isshouji = option.isshouji
			}
		},
		methods: {
			back() { //返回
				uni.navigateBack({
					delta: 1
				})
			},
			toSupplement: function() {
				uni.navigateTo({
					url: '../supplement/supplement'
				})
			},
			bindClearInput: function(e) { //显示隐藏清除键
				this.inputClearValue = e.target.value;
				if (e.target.value.length > 0) {
					this.showClearIcon = true;
				} else {
					this.showClearIcon = false;
				}
			},
			clearIcon: function() { //清除内容
				this.inputClearValue = "";
				this.showClearIcon = false;
			},
			toSetPass() {
				var data = {
					login_pass: this.newPass,
					user_id: uni.getStorageSync('user_id')
				}
				this.myAjaxNewPost({
					model: 'user',
					controllerName: 'user',
					actionName: 'update',
					data: data,
					successBack: function(res) {
						console.log(res.data)
						if (res.data.message == '成功') {
				
							uni.navigateBack({
								delta: 3
							})
							uni.showToast({
								title: '密码修改成功',
								icon: 'none'
							})
						}
					},
				})
			},
		},
	}
</script>

<style scoped>
	.bg {
		background: #ffffff;
		height: 100%;
	}

	.head {
		width: 128upx;
		background: #FFFFFF;
		display: flex;
		justify-content: space-between;
		align-items: center;
		color: #333333;
		width: 100%;
		padding: 0 24upx;
	}

	.head_right {
		width: 45upx;
	}

	.body {
		margin-top: 40upx;
		margin-bottom: 88upx;
	}

	.head image {
		width: 21upx;
		height: 36upx;
	}

	.body_item {
		border-bottom: 1upx solid #E6E6E6;
		display: flex;
		align-items: center;
		padding: 20upx 24upx;
		font-size: 28upx;
		color: #333333;

	}

	.body_item .passimg {
		width: 46upx;
		height: 40upx;
		margin-right: 20upx;
	}

	.body_item .delete {
		width: 28upx;
		height: 28upx;
	}

	.body_item input {
		width: 100%;

	}
</style>
